/* 
 *  <copyright file="SceneGameService.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;



namespace SobrietyEngine.Scene
{
    public class SceneGameService:DrawableGameComponent, ISceneGameService
    {

        public Dictionary<String, IScene> Scenes { get; set; }

        public SceneGameService(Game game)
            : base(game)
        {
            Scenes = new Dictionary<string, IScene>();
            Game.Services.AddService(typeof(ISceneGameService), this);            
        }

        public void AddScene(String sceneName, IScene scene)
        {
            if (Scenes.ContainsKey(sceneName))
            {
                Logging.Logger.GetSingleton().WriteError("Scene with this name already exists");
            }
            else
            {
                Scenes.Add(sceneName, scene);
                scene.Initialize();
            }
        }

        public override void Initialize()
        {
            base.Initialize();
        }        


        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            foreach (IScene scene in Scenes.Values)
            {
                if(scene.Active)
                    scene.Update(gameTime);
            }
        }

        public void ManualDraw(GameTime gameTime)
        {
            foreach (IScene scene in Scenes.Values)
            {
                if(scene.Active)
                    scene.ManualDraw(gameTime);
            }
        }
    }
}